﻿using Prices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace Prices
{

    [TestClass()]
    public class PriceTest
    {

        [TestMethod()]
        public void PriceConstructorTest()
        {
            string name = "Bread"; 
            Decimal price = new Decimal(5.5); 
            Price target = new Price(name, price);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void PriceConstructorWithNullNameTest()
        {
            string name = null; 
            Decimal price = new Decimal(5.5); 
            Price target = new Price(name, price);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void PriceConstructorWithNegativePriceTest()
        {
            string name = "Bread";
            Decimal price = new Decimal(-5.5);
            Price target = new Price(name, price);
        }

        [TestMethod()]
        public void CurrentPriceTest()
        {
            string name = "Bread"; 
            Decimal price = new Decimal(5); 
            Price target = new Price(name, price); 
            Decimal expected = new Decimal(5); 
            Decimal actual;
            target.CurrentPrice = expected;
            actual = target.CurrentPrice;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void NameTest()
        {
            string name = "Tomato"; 
            Decimal price = new Decimal(20); 
            Price target = new Price(name, price);
            string expected = "Tomato";
            string actual;
            target.Name = expected;
            actual = target.Name;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void WasEventFiredOnPriceChangedWithBiggerPriceTest()
        {
            string name = "Bread";
            Decimal price = new Decimal(5);
            Price target = new Price(name, price);
            bool expected = true;
            target.CurrentPrice = 8;
            bool actual = target.WasPriceChanged;
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void WasEventFiredOnPriceChangedLowerPriceTest()
        {
            string name = "Bread";
            Decimal price = new Decimal(5);
            Price target = new Price(name, price);
            bool expected =false;
            target.CurrentPrice = 4;
            bool actual = target.WasPriceChanged;
            Assert.AreEqual(expected, actual);
        }
    }
}
